#! /usr/bin/env bash

set -e

PROJECT_DIR=$(cd $(dirname $0) > /dev/null && pwd)
privateKey=$1

date=$(date +%Y-%m-%d)

target="manage"${date}".zip"


function usage() {
    echo "Deploy, Usage: "
    echo "\t sh deploy.sh privateKey # for build production."
    echo "\t privateKey is ssh private key file"
}

if [ "$#" -lt 1 ]; then
    usage
    exit 1
fi

echo "build project"

rm -rf manage
npm run build

echo "start deploy"

zip -r $target manage

scp   -i $privateKey $target gift@47.75.132.53:~   

ssh  -i $privateKey gift@47.75.132.53 "sh frontend-deploy.sh $target; exit"

rm -f ${target}
rm -rf manage
echo "Deploy is ok"